<!-- JSP to manage departments -->
<%@ page import="sg.edu.nus.iss.cats.controller.*,sg.edu.nus.iss.cats.model.*,sg.edu.nus.iss.cats.dataaccess.DAOException"%>


<% 
    
    String departmentId = request.getParameter("departmentid");
    String managerInCharge = request.getParameter("managerincharge");

    if (departmentId == null || managerInCharge == null || 
        departmentId.equals("") || managerInCharge.equals("")){
        HTMLUtil.displayException(request,response,"Sorry, the department details could not be added. \n Please check the department id and manager-in-charge.....");
        return;
    }
    
    Department newDepartment = new Department();  
    newDepartment.setDepartmentId(departmentId);
    newDepartment.setManagerInCharge(managerInCharge);

    try{

        DepartmentManager departmentManager = new DepartmentManager();
        departmentManager.insertDepartment (newDepartment);

    }catch(DAOException e){
        HTMLUtil.displayException(request,response,"Sorry, the department could not be updated.");
        return;

    }
 %>
 
 <!-- Forward to page which lists users -->    
 <jsp:forward page="/admin/displayDept" />